package com.example.rest.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.base.jdbc.DBSql;
import com.example.base.jdbc.SqlBuilder;
import com.example.base.security.SecurityUtil;
import com.example.base.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/test")
public class TestDemoController {

    @GetMapping("/info")
    public JSONObject infoController() throws IOException, SQLException {
        List<Map<String,Object>> mapList=DBSql.getMaps("select * from sys_job");
        return Result.successInfo(mapList);
    }

    @PostMapping("/test")
    public JSONObject testController(@RequestParam("pageNum")Integer pageNum,
                                     @RequestParam("pageSize")Integer pageSize,
                                     @RequestParam("name")String name) throws IOException, SQLException {
        SecurityUtil.getSysUserEntity();
        log.info("page{}",pageNum);
        SqlBuilder sqlBuilder=new SqlBuilder();
        sqlBuilder.select("*").from("sys_menu");
        sqlBuilder.and("component").eq(name);
        List<Map<String,Object>> mapList=DBSql.getMaps(sqlBuilder.getSql(),sqlBuilder.getObjects());

        return Result.successInfo(mapList);
    }
}
